package eteam.aps.systemservice.config;

import com.github.xiaoymin.knife4j.spring.annotations.EnableKnife4j;
import io.swagger.annotations.ApiOperation;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2WebMvc;

/**
 * Swagger文档配置类
 */
@Configuration
@EnableKnife4j
@EnableSwagger2WebMvc
public class SystemServiceKnife4jConfig {
    @Bean(value = "systemApi2")
    public Docket systemApi2() {
        Docket docket = new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(new ApiInfoBuilder()
                        .title("系统服务")
                        .description("# 系统服务 - Api接口文档")
                        .termsOfServiceUrl("http://localhost:9006/")
                        .contact(new Contact("xx", null, "xx@qq.com"))
                        .version("1.0-SNAPSHOT")
                        .build())
                //分组名称
                .groupName("SystemService")
                .select()
                //这里指定Controller扫描包路径
                //.apis(RequestHandlerSelectors.basePackage("eteam.aps.systemservice.service"))
                .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
                //.paths(Predicates.not(PathSelectors.regex("/error.*")))//错误路径不监控
                .paths(PathSelectors.any())
                .build();
        return docket;
    }

//    private ApiKey apiKey() {
//        return new ApiKey("BearerToken", "Authorization", "header");
//    }
//    private ApiKey apiKey1() {
//        return new ApiKey("BearerToken1", "Authorization-x", "header");
//    }
//    private SecurityContext securityContext() {
//        return SecurityContext.builder()
//                .securityReferences(defaultAuth())
//                .forPaths(PathSelectors.regex("/.*"))
//                .build();
//    }
//    private SecurityContext securityContext1() {
//        return SecurityContext.builder()
//                .securityReferences(defaultAuth1())
//                .forPaths(PathSelectors.regex("/.*"))
//                .build();
//    }
//    List<SecurityReference> defaultAuth() {
//        AuthorizationScope authorizationScope = new AuthorizationScope("global", "accessEverything");
//        AuthorizationScope[] authorizationScopes = new AuthorizationScope[1];
//        authorizationScopes[0] = authorizationScope;
//        return CollectionUtils.newArrayList(new SecurityReference("BearerToken", authorizationScopes));
//    }
//    List<SecurityReference> defaultAuth1() {
//        AuthorizationScope authorizationScope = new AuthorizationScope("global", "accessEverything");
//        AuthorizationScope[] authorizationScopes = new AuthorizationScope[1];
//        authorizationScopes[0] = authorizationScope;
//        return CollectionUtils.newArrayList(new SecurityReference("BearerToken1", authorizationScopes));
//    }
}
